package com.ruoyi.web.controller.byhealth;

import com.alibaba.fastjson.JSON;
import com.ruoyi.by.health.domain.form.SystemConfigParam;
import com.ruoyi.common.core.domain.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

/**
 * @ClassName ByhealthAdminController
 * @Author 张敬琦
 * @Description 添加描述
 * @Date 2024/1/22 01:09
 **/
@Slf4j
@Api(value = "管理云接口", tags = "管理员接口")
@RestController
@RequestMapping("/byhealth/admin")
public class ByhealthAdminController {

    @Resource
    RedisTemplate<String, Object> redisTemplate;

    /**
     * 获取小程序配置信息
     *
     * @return 小程序配置信息
     */
    @ApiOperation("获取小程序配置信息")
    @GetMapping("getConfigList")
    public AjaxResult getConfigList() {

        Map<Object, Object> entries = redisTemplate.opsForHash().entries("byhealth_system_config");
        return AjaxResult.success(entries);
    }
    /**
     * 更新小程序配置信息
     *
     * @return 更新小程序配置信息
     */
    @ApiOperation("更新小程序配置信息")
    @PostMapping("updateConfig")
    public AjaxResult updateConfig(@RequestBody SystemConfigParam configParam) {

        log.info("updateConfig:" + configParam.toString());
        redisTemplate.opsForHash().put("byhealth_system_config", configParam.getKey(), configParam.getValue() );
        Map<Object, Object> entries =    redisTemplate.opsForHash().entries("byhealth_system_config");
        log.info("updateConfig.entries:{}:" + JSON.toJSONString(entries));
        return AjaxResult.success();
    }

}
